package com.zline.foodraise.wxapi;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import com.tencent.mm.sdk.modelbase.BaseReq;
import com.tencent.mm.sdk.modelbase.BaseResp;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.sdk.openapi.WXAPIFactory;
import com.zline.foodraise.constant.Constant;
import com.zline.foodraise.entity.AppPref_;
import com.zline.foodraise.ui.activity.MainActivity_;
import com.zline.foodraise.ui.activity.TemplateShareActivity_;
import com.zline.foodraise.util.LUtil;

public class WXEntryActivity extends Activity implements IWXAPIEventHandler {
    private static final String LOG_TAG = WXEntryActivity.class.getSimpleName();
    private IWXAPI api;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        api = WXAPIFactory.createWXAPI(this, Constant.WX_APP_ID, false);
        api.handleIntent(getIntent(), this);

    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);
        api.handleIntent(intent, this);
    }


    @Override
    public void onReq(BaseReq baseReq) {

    }

    //接收返回状态
    @Override
    public void onResp(BaseResp baseResp) {
        String result = "";
        int where2Share;
        switch (baseResp.errCode) {
            case BaseResp.ErrCode.ERR_OK://发送成功
                result = "分享成功";
                LUtil.i(LOG_TAG, "_______成功发送_________");
                break;
            case BaseResp.ErrCode.ERR_USER_CANCEL://发送取消
                result = "分享失败";
                LUtil.i(LOG_TAG, "_______取消发送_________");
                break;
            case BaseResp.ErrCode.ERR_AUTH_DENIED://发送被拒绝
                LUtil.i(LOG_TAG, "_______拒绝发送_________");
                result = "分享被拒绝";
                break;
            default:
                break;
        }
        AppPref_ appPref = new AppPref_(this);
        appPref.edit().shareResult().put(result).apply();
        finish();
    }
}